package com.futvan.z.framework.tags;

import java.util.List;

import javax.servlet.jsp.JspException;

import com.futvan.z.framework.core.SuperTag;
import com.futvan.z.framework.core.z;
import com.futvan.z.system.cms_column.cms_column;
import com.futvan.z.system.cms_info.cms_info;
import com.futvan.z.system.zcode.z_code;
import com.futvan.z.system.zcode.z_code_detail;

public class newsBox extends SuperTag {
	private String columnId;
	private String box_size;

	@Override
	public int doEndTag() throws JspException {
		StringBuffer out_html = new StringBuffer();
		try {
			if(z.isNotNull(columnId)) {
				cms_column col = z.cmsColumnForNumber.get(columnId);
				if("1".equals(col.getIs_parent_display())) {
					
					if(z.isNull(box_size)) {
						out_html.append("<div class=\"col-md-"+col.getBox_size()+"\">").append("\r\n");
					}else {
						out_html.append("<div class=\"col-md-"+box_size+"\">").append("\r\n");
					}
					
					//判读是否在新窗口打开
					String target = "";
					if("1".equals(col.getIsblank())) {
						target = " target=\"_blank\" ";
					}
					
					
					//获取栏目下所有资讯
					List<cms_info> cmslist = z.cmsList.get(col.getZid());

					//获取所有子栏目
					List<cms_column> dcolumnList = z.cmsColumnDetail.get(col.getZid());
					for (cms_column dcol : dcolumnList) {
						cmslist.addAll(z.cmsList.get(dcol.getZid()));
					}

					out_html.append("<div class=\"row p-3\">").append("\r\n");
					out_html.append("	<div class=\"col-md-12 newsBox_bc1\">").append("\r\n");
					out_html.append("		<div class=\"row\">").append("\r\n");
					out_html.append("			<div class=\"col-md-8 text-left newsBoxTitleImg text-truncate\">"+col.getColumn_name()+"</div>").append("\r\n");
					
					//如果栏目为独立栏目，不显示更多按钮
					if(!"3".equals(col.getColumn_type())) {
						out_html.append("			<div class=\"col-md-4 text-right\">").append("\r\n");
						out_html.append("<a class=\"clearA\" href=\""+col.getUrl()+"\" "+target+">更多 <i class=\"fa fa-angle-right\"></i></a>").append("\r\n");
						out_html.append("			</div>").append("\r\n");
					}
					out_html.append("		</div>").append("\r\n");
					out_html.append("	</div>").append("\r\n");
					out_html.append("	<div class=\"col-md-12 pt-2\">").append("\r\n");
					
					//根据栏目类型不同，显示不同信息  0 = 新闻集 | 1 = 图片集 | 2 = 视频集 | 3 = 独立栏目【显示图文】
					if("3".equals(col.getColumn_type())) {
						if(z.isNull(col.getImg())) {
							col.setImg("img/web/zw.jpg");
						}
						out_html.append("		<a class=\"clearA\" href=\""+col.getUrl()+"\" "+target+"><img src=\""+col.getImg()+"\" width=\"100%\" height=\"210px\"></a>").append("\r\n");
					}else {
						//非独立栏目
						if(!cmslist.isEmpty()) {
							cms_info firstCms = cmslist.get(0);
							if(z.isNotNull(firstCms)){
								if(z.isNull(firstCms.getImg1())) {
									firstCms.setImg1("img/web/zw.jpg");
								}
								
								//判读是否在新窗口打开
								String targetfirstCms = "";
								if("1".equals(firstCms.getIsblank())) {
									targetfirstCms = " target=\"_blank\" ";
								}
								
								if("0".equals(firstCms.getCms_type())) {
									out_html.append("		<a class=\"clearA\" href=\"open_cms?zid="+firstCms.getZid()+"\" "+targetfirstCms+"><img src=\""+firstCms.getImg1()+"\" width=\"100%\" height=\"210px\"></a>").append("\r\n");
								}else if("1".equals(firstCms.getCms_type())) {
									out_html.append("		<a class=\"clearA\" href=\"open_cms?zid="+firstCms.getZid()+"\" "+targetfirstCms+"><img src=\""+firstCms.getImg1()+"\" width=\"100%\" height=\"210px\"></a>").append("\r\n");
								}else if("2".equals(firstCms.getCms_type())) {
									out_html.append("		<video src=\""+firstCms.getVideo()+"\" controls=\"true\" poster=\""+firstCms.getImg1()+"\" width=\"100%\" height=\"210px\"/>").append("\r\n");
								}else if("3".equals(firstCms.getCms_type())) {
									out_html.append("		<a class=\"clearA\" href=\"open_cms?zid="+firstCms.getZid()+"\" "+targetfirstCms+"><img src=\""+firstCms.getImg1()+"\" width=\"100%\" height=\"210px\"></a>").append("\r\n");
								}else if("4".equals(firstCms.getCms_type())) {
									out_html.append("		<a class=\"clearA\" href=\"open_cms?zid="+firstCms.getZid()+"\" "+targetfirstCms+"><img src=\""+firstCms.getImg1()+"\" width=\"100%\" height=\"210px\"></a>").append("\r\n");
								}
							}
						}
						
						
					}
					

					out_html.append("	</div>").append("\r\n");
					out_html.append("	<div class=\"col-md-12 pt-2\">").append("\r\n");
					out_html.append("		<div class=\"row\">").append("\r\n");
					
					//根据栏目类型不同，显示不同信息  0 = 新闻集 | 1 = 图片集 | 2 = 视频集 | 3 = 独立栏目【显示图文】
					if("3".equals(col.getColumn_type())) {
						out_html.append("			<div class=\"col-md-12 newsBox_title1 text-truncate\"><a class=\"clearA\" href=\""+col.getUrl()+"\" "+target+">"+col.getTitle1()+"</a></div>").append("\r\n");
					}else {
						int i=0;
						for (cms_info c : cmslist) {
							if(i<1) {
								
								//判读是否在新窗口打开
								String targetc = "";
								if("1".equals(c.getIsblank())) {
									targetc = " target=\"_blank\" ";
								}
								
								out_html.append("			<div class=\"col-md-12 newsBox_title1 text-truncate\"><a class=\"clearA\" href=\"open_cms?zid="+c.getZid()+"\" "+targetc+">"+c.getTitle1()+"</a></div>").append("\r\n");
								i = i+1;
							}
						}
					}
					
					out_html.append("		</div>").append("\r\n");
					out_html.append("	</div>").append("\r\n");
					out_html.append("</div>").append("\r\n");	
					out_html.append("</div>").append("\r\n");	
				}
			}
			outHTML(out_html.toString());
		} catch (Exception e) {
			z.Error("newBos error", e);
		}
		return super.doEndTag();
	}

	public String getColumnId() {
		return columnId;
	}

	public void setColumnId(String columnId) {
		this.columnId = columnId;
	}

	public String getBox_size() {
		return box_size;
	}

	public void setBox_size(String box_size) {
		this.box_size = box_size;
	}



}
